package com.corpgovernment.permission.service;

import com.corpgovernment.permission.entity.db.Menu;
import com.corpgovernment.permission.mapper.MenuMapper;
import com.ctrip.corp.obt.generic.core.context.TenantContext;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

@Service
@Slf4j
public class MenuServiceImpl implements MenuService{

    @Autowired
    private MenuMapper menuMapper;
    @Autowired
    MenuService menuService;

    @Override
    public List<Menu> getMenuByIds(List<Long> ids){
        return Optional.ofNullable(TenantContext.ignoreTenantContext(()->menuService.getMenuByIdList(ids))).orElse(new ArrayList<>());
    }

    @Transactional(propagation= Propagation.REQUIRES_NEW)
    public List<Menu> getMenuByIdList(List<Long> ids){
        return menuMapper.getMenuByIds(ids);
    }
}
